with c as (
  select
    st.source,
    st.trip_id as trip_id,
    t.service_id,
    st.source || '_' || st.trip_id || '_' || st.stop_sequence  as conn_id,

    st.stop_id as from_stop_id,
    st.source || '_' || vsp.parent_station as from_stop_sidu,
    vsp.parent_station as from_stop_idu,
    st.departure_time as from_stop_time,
    st.stop_sequence as from_stop_sequence,

    lead(st.stop_id) over (partition by st.source, st.trip_id order by st.stop_sequence) as to_stop_id,
    lead(vsp.parent_station) over (partition by st.source, st.trip_id order by st.stop_sequence) as to_stop_idu,
    lead(st.departure_time) over (partition by st.source, st.trip_id order by st.stop_sequence) as to_stop_time,
    lead(st.stop_sequence) over (partition by st.source, st.trip_id order by st.stop_sequence) as to_stop_sequence,
    st.source || '_' || lead(vsp.parent_station) over (partition by st.source, st.trip_id order by st.stop_sequence) as to_stop_sidu
  from stop_times as st
  inner join _vstopparent as vsp on st.stop_id = vsp.stop_id and st.source = vsp.source
  join trips t on st.trip_id = t.trip_id and t.source = st.source
  order by from_stop_time
)
select * from c where to_stop_sequence is not null
